package de.schiess.main;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.StringTokenizer;



public class PriceFile {
	public static boolean get(){
		 try
	      {
	          URL url  = new URL("http://supernovabots.com/prices_0.txt");
	          System.out.println("Opening connection to " + url.getPath() + "...");
	          URLConnection urlC = url.openConnection();
	          // Copy resource to local file, use remote file
	          // if no local file name specified
	          InputStream is = url.openStream();
	          // Print info about resource
	          System.out.print("Copying resource (type: " +
	                           urlC.getContentType());
	          Date date=new Date(urlC.getLastModified());
	          System.out.println(", modified on: " +
	             date.toLocaleString() + ")...");
	          System.out.flush();
	          FileOutputStream fos=null;
	          if (true)
	          {
	              String localFile=null;
	              // Get only file name
	              StringTokenizer st=new StringTokenizer(url.getFile(), "/");
	              while (st.hasMoreTokens())
	                     localFile=st.nextToken();
	              fos = new FileOutputStream(localFile);
	          }
//	          else
//	              fos = new FileOutputStream(args[1]);
	          int oneChar, count=0;
	          while ((oneChar=is.read()) != -1)
	          {
	             fos.write(oneChar);
	             count++;
	          }
	          is.close();
	          
	          fos.close();
	          System.out.println(count + " byte(s) copied");
	      }
	      catch (MalformedURLException e){
	    	  return false;
	    	  
	      }
	      catch (IOException e)
	      { return false; }
	      return true;
	  }
				
	}

